<?php
namespace app\admin\controller;
use app\admin\validate\UserValidate;
use app\admin\model\OrderModer;
use think\facade\Request;
class Order extends UserValidate{
    /**
     * 首页
     * @return \think\response\View
     */
    public function index(){
        $order_list = (new OrderModer)->index();
        $this->assign('order_list',$order_list);
        return view();
    }

    /**
     * 获取全部商家
     */
    public function indexs(){
        $shop = (new OrderModer)->indexshop();
        $this->assign('ordershop',$shop);
        return view();
    }
    /**
     * 单个商家订单
     */
    public function shopid(){
        $ma_id = (int)input('ma_id');
        $shoporder = (new OrderModer)->indexshopid($ma_id);
        $this->assign('order_list',$shoporder);
        $this->assign('ma_id',$ma_id);
        return $this->fetch('index');

    }
    /**
     * 订单管理
     * 状态 1未支付，2已支付，3 已完成，4 已退款
     * @return \think\response\View
     */
    public function order_add(){
        $or_status = (int)input('or_status');
        if ((int)input('ma_id')){
            $ma_id = (int)input('ma_id');
        }else{
            $ma_id = '';
        }
        if (empty($or_status)){
            $this->error('错误');
        }
        $or_status_list = (new OrderModer)->order_add($or_status,$ma_id);
        $this->assign('order_list',$or_status_list);
        $this->assign('ma_id',$ma_id);
        return $this->fetch('index');
    }
    /**
     * 订单详情
     */
    public function order_details(){
        if (empty(input('or_ordersn'))){
            $this->error('缺少重要参数');
        }
        $or_ordersn = input('or_ordersn');
        $details = (new OrderModer)->order_details($or_ordersn);
        $this->assign('list',$details);
        return $this->fetch();
    }

    /**
     * 搜索
     * @or_ordersn 订单号
     * @return mixed
     */
    public function order_search(){
        if (empty(Request::get('or_ordersn'))){
            $this->error('请输入参数');
        }
        $details = (new OrderModer)->order_search(Request::get('or_ordersn'));
        $this->assign('order_list',$details);
        return $this->fetch('index');
    }

    /**
     * 月,季,年
     * @return mixed
     */
    public function ordermonth(){
        $or = input('or');
        $details = (new OrderModer)->month($or);
        if ($details === null){
            $this->error('暂无数据');
        }
        $this->assign('order_list',$details);
        return $this->fetch('order/index');
    }
}